/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.mall.common.web.StaticPageAction
   Module Description   :

   Date Created      : 2009/12/14
   Original Author   : feeling.wang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.mall.member.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.common.utils.ServerValue;
import com.yaodian100.mall.member.util.UserData;

/**
 * @author feeling.wang
 * 
 */
public class StaticPageAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = -4313849062849659886L;
	/** logger */
	private final Logger logger = LoggerFactory.getLogger(StaticPageAction.class);
	private String type;
	private String page;
	private String filePath;
	private String pageContext;
	private final String subFileName = ".html";
	private StringBuffer sb;
	UserData userData = null;

	/**
	 * 歷史訂單(2个月之前的所有订单资料)
	 * 
	 * @return
	 * @throws Exception
	 */
	public String displayHistoryOrder() throws Exception {
		filePath = getOrderPath("H", page);
		return "static";
	}

	/**
	 * 订单查询-所有订单(2个月内的订单资料)-匯款招領用
	 * 
	 * @return
	 * @throws Exception
	 */
	public String displayMyOrder() throws Exception {
		filePath = getOrderPath("T", page);
		return "showMyOrder";
	}

	/**
	 * 订单查询-所有订单(2个月内的订单资料)
	 * 
	 * @return
	 * @throws Exception
	 */
	public String displayOrder() throws Exception {
		filePath = getOrderPath("T", page);
		return "static";
	}

	/**
	 * 尚未支付的订单资料(2个月内的订单，尚未支付的资料)
	 * 
	 * @return
	 * @throws Exception
	 */
	public String displayYetPaymentOrder() throws Exception {
		filePath = getOrderPath("Y", page);
		return "static";
	}

	public String getFilePath() {
		return filePath;
	}

	/**
	 * 传入订单类型及页数组出路径
	 * 
	 * @param type
	 * @param page
	 * @return
	 */
	String getOrderPath(String type, String page) {
		if (StringUtils.isBlank(page))
			page = "1";
		sb = new StringBuffer().append(ServerValue.getFrontOrderHtmlPath()).append("/").append(
				userData.getMemberId().substring(0, 4)).append("/").append(userData.getMemberId().substring(4, 8)).append("/")
				.append(userData.getMemberId()).append("/").append(userData.getMemberId()).append("_").append(type).append("_")
				.append(page).append(subFileName);
		String path = sb.toString();
		sb.setLength(0);
		return path;
	}

	public String getPage() {
		return page;
	}

	public String getPageContext() {
		return pageContext;
	}

	public String getType() {
		return type;
	}

	
	public void prepare() throws Exception {
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		if (null == userData)
			userData = new UserData(request, response);
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public void setPageContext(String pageContext) {
		this.pageContext = pageContext;
	}

	public void setType(String type) {
		this.type = type;
	}
}